/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class BlockColor extends Shape{
    Point[] ll;
    int n;
    Color color;
    int oldColor;
    public BlockColor( Point[] ll,int n1,Color color ,int oldColor){
        n=n1;
        this.ll=ll;
        this.color=color;
        this.oldColor=oldColor;
    }
    
    public void addPoint(Point point){
        if(n==0)
        {
            n++;
            ll=new Point[n];
            ll[0]=point;
        }
        else
        {
            n++;
            Point[] t=new Point[n];
            for(int i=0;i<n-1;i++)
            {
                t[i]=ll[i];
            }
            t[n-1]=point;
            ll=t;
        }
    }


    @Override
    public void drawShape(Graphics g, BufferedImage a) {

        
    }
    
    public void undo(BufferedImage a){
        for(int i=0;i<n;i++){
            a.setRGB(ll[i].getX(), ll[i].getY(), oldColor);
        }
    }
    
    public void redo(BufferedImage a){
         WritableRaster wr = a.getRaster();
                int[] color1= new int[3];
                color1[0]=color.getRed();
                color1[1]=color.getGreen();
                color1[2]=color.getBlue();
        for(int i=0;i<n;i++){
            wr.setPixel(ll[i].getX(), ll[i].getY(), color1);
        }
    }

    @Override
    public void toMove(int x, int y) {

    }


    @Override
    public boolean isContain(Point p) {
        return false;
    }
    
    @Override
    public void replay(Graphics g, int time,Image a,Control.NewClass.MyPanel1 a2) {
                for(int i=0;i<n;i++){
            ((BufferedImage)a).setRGB(ll[i].getX(), ll[i].getY(), color.getRGB());
        }
                g.drawImage(a, 0, 0, a2);
        try {
            Thread.sleep(time*5);
        } catch (InterruptedException ex) {
            Logger.getLogger(BlockColor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
